<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace support\utils;

class Str
{
    /**
     * 格式化归0金额
     * 1.00 => 1
     * 1.10 => 1.1
     * 1.01 => 1.01.
     * @return string
     */
    public static function formatMoney($price): string
    {
        return strval(floatval($price));
    }

    /**
     * 格式化归0金额
     * 1 => 1.00
     * 1.1 => 1.10
     * 1.01 => 1.01.
     * @param mixed $scale
     * @return string
     */
    public static function formatDecimal($price, $scale = 2): string
    {
        return sprintf("%.{$scale}f", $price);
    }

    /**
     * @return string
     */
    public static function formatInt($num): string
    {
        return strval(intval($num));
    }
}
